package com.spring.adapter;

import com.spring.gowhere.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class LocationAdapter extends BaseAdapter {
	private Context context;
	private String[] location;
	private String locationtype;

	public LocationAdapter(Context context, String locationtype) {
		this.locationtype = locationtype;
		this.context = context;
	}

	public String[] getLocation() {
		return location;
	}

	public void setLocation(String[] location) {
		this.location = location;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return location.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return location[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.indicators_item, null);
			viewHolder.progname = (TextView) convertView
					.findViewById(R.id.indicators_progname);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (locationtype.equalsIgnoreCase("0")) {
			convertView.findViewById(R.id.progimage).setVisibility(View.GONE);
			convertView.findViewById(R.id.imageselect).setVisibility(View.GONE);

		} else {
			convertView.findViewById(R.id.progimage)
					.setVisibility(View.VISIBLE);
			convertView.findViewById(R.id.imageselect).setVisibility(
					View.VISIBLE);
		}
		viewHolder.progname.setText(location[position]);

		return convertView;
	}

	public class ViewHolder {
		TextView progname;
	}
}
